package shoooter.entity.nonimage;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import shoooter.entity.nonimage.enemy.Enemy;
import shoooter.geometry.Vec2;


public class Bomb extends Explosives {

    int rad;
    int start_rad = 6;
    int max_rad = 24;

    public boolean exploding = false;

    public Bomb(Vec2 vPos) {
        this(vPos, 150);
    }

    public Bomb(Vec2 vPos, int time) {
        this.vPos = new Vec2(vPos);
        this.time_limit = time;
        this.rad = start_rad;
        this.damage = 10;
    }

    public boolean elapse() {

        time++;
        double dd;

        if( exploding && time > time_limit )
            return false;

        if(!exploding) {    
            if(time >= time_limit) {
                exploding = true;
                time = 0;       // riusa time
            }
        }
        else {
            if((time % 4) == 0) {
                dd = ((double)this.start_rad);
                this.rad = (int) (dd*(1.0d+1.0*(((double)(max_rad-start_rad))*((double)time/time_limit))));
            }
        }
        return true;
    }

    public void hit(Enemy[] enemies) {

        for(Enemy e: enemies)
            if(e!=null)
                if( (Vec2.distance(vPos, e.getvPos())) < (this.rad + e.rad) )
                 e.hit(this.damage);

    }

    public void hit1(Player p) {
        if( (Vec2.distance(vPos, p.getvPos())) < (this.rad + p.rad) )
            p.hit(1);
    }

    public void draw(Graphics2D g2d) {


        Font f = g2d.getFont();
        g2d.setFont(new Font(f.getName(), Font.BOLD, f.getSize()-2));

        g2d.setColor(Color.yellow);
        g2d.fillOval((int) this.getX() - this.rad, (int) this.getY() - this.rad, this.rad*2, this.rad*2);
        
        g2d.setColor(Color.black);
        g2d.drawOval((int) this.getX() - this.rad, (int) this.getY() - this.rad, this.rad*2, this.rad*2);

        if(!exploding)
            g2d.drawString(String.valueOf(3 - (int)time/50), (int)this.getX() - 3, (int)this.getY() + 4);

        g2d.setFont(f);

    }
}